home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6267 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  65 lines

  1. Path: newsfeed.internetmci.com!panix!not-for-mail
  2. From: lmb@panix.com (Lance Ball)
  3. Newsgroups: comp.lang.c
  4. Subject: pointer to pointer to int
  5. Date: 23 Feb 1996 11:43:46 -0500
  6. Organization: PANIX Public Access Internet and UNIX, NYC
  7. Message-ID: <4gkqs2$gbn@panix2.panix.com>
  8. NNTP-Posting-Host: panix2.panix.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. Hi.  I'm trying to emulate a very basic CPU scheduler for an OS class
  12. and I keep getting a core dump with my code.  It compiles fine, but I
  13. can't run it.  Here is what I am doing (sorta'):
  14.  
  15. struct PCB {
  16.     int *programCounter;
  17.     void *localvars;
  18.     void (*proc)(void);
  19. } proctable[MAX_PROC];
  20.  
  21. int *pc;    // global
  22. void *lv;    //global
  23. void badproc(void);
  24.  
  25. int main(void)
  26. {
  27.     int count = 100;
  28.     int curprocess;
  29.     PCB *pp = new PCB;
  30.     while (count > 0) {
  31.         curprocess = rand()%MAX_PROCS;
  32.         *pp = proctable[curprocess];
  33.         pp->programCounter = 0;
  34.         pc = pp->programCounter;
  35.     // more code
  36.         pp->proc = badproc;
  37.         (pp->proc)();
  38.         count--;
  39.     }
  40. return 0;
  41. }
  42.  
  43. void badproc(void)
  44. {
  45. switch(*pc) {
  46.     case 0:    statement1;    *pc++;    break;
  47.     case 1:    statement2;    *pc++;    break;
  48.     .
  49.     .
  50.     .
  51. }
  52.  
  53. Anyway, the problem seems to be with the *pc variable, but I can't 
  54. pinpoint where.  Does anyone have any ideas about how I might be
  55. able to execute this code?
  56.  
  57. Thanks,
  58.  
  59. LB
  60. -- 
  61. Lance M. Ball             |Imagination is greater than knowledge. -A.E. 
  62. adobe theatre co.        |    lmb@panix.com
  63. http://www.panix.com/~lmb/adobe    |    lball@stern.nyu.edu
  64.  
  65.